using UnityEngine;

namespace FreeDraw
{
	public class DrawingSettings : MonoBehaviour
	{
		public static bool isCursorOverUI;

		public float Transparency = 1f;

		private void Awake()
		{
			ColorButton.OnColorButtonClicked += OnColorChanged;
		}

		private void OnDestroy()
		{
			ColorButton.OnColorButtonClicked -= OnColorChanged;
		}

		public void SetMarkerColour(Color new_color)
		{
			Drawable.Pen_Colour = new_color;
		}

		public void SetMarkerWidth(int new_width)
		{
			Drawable.Pen_Width = new_width;
		}

		public void SetMarkerWidth(float new_width)
		{
			SetMarkerWidth((int)new_width);
		}

		public void SetTransparency(float amount)
		{
			Transparency = amount;
			Color pen_Colour = Drawable.Pen_Colour;
			pen_Colour.a = amount;
			Drawable.Pen_Colour = pen_Colour;
		}

		public void SetMarkerRed()
		{
			Color red = Color.red;
			red.a = Transparency;
			SetMarkerColour(red);
			Drawable.drawable.SetPenBrush();
		}

		public void SetMarkerGreen()
		{
			Color green = Color.green;
			green.a = Transparency;
			SetMarkerColour(green);
			Drawable.drawable.SetPenBrush();
		}

		public void SetMarkerBlue()
		{
			Color blue = Color.blue;
			blue.a = Transparency;
			SetMarkerColour(blue);
			Drawable.drawable.SetPenBrush();
		}

		public void SetEraser()
		{
			SetMarkerColour(new Color(255f, 255f, 255f, 0f));
		}

		public void PartialSetEraser()
		{
			SetMarkerColour(new Color(255f, 255f, 255f, 0.5f));
		}

		private void OnColorChanged(Color _NewColor)
		{
			Color markerColour = _NewColor;
			markerColour.a = Transparency;
			SetMarkerColour(markerColour);
			Drawable.drawable.SetPenBrush();
		}
	}
}
